<?php
//error_reporting(E_ALL);ini_set("display_errors", "On");
class Admin_pageController extends Controller {

	public $layout = false;
	public $secure = true;
	
	public $models = array("Admin", "Pages");
	
	public function edit($id) {
		
		$page = $this->Pages->findRow("*", array("id"=>$id));
		if($page) {
			$this->assign("page", $page);
			$this->assign("title", $this->template_parser->get_config_vars($page["name"]));
		}else{
			die("nema.");
		}
		
		$this->display("admin/_page.html");
		$this->session_set("message","");
		$this->session_set("message_class","");
		$this->session_set("form_data",array());
	}
	
	public function save($id) {
		$data = $this->data;
		
		$ret = $this->Pages->update($this->data, array("id"=>$id));
		if ($ret) {
			$ok = true;
			$message = "Sačuvano.";
		}else{
			$ok = false;
			$message = "Greška!";
		}
		
		$this->session_set("message", $message);
		$this->session_set("message_class", $ok?"ok":"error");
		$this->session_set("form_data", $ok?array():$this->data);
		redirect("/admin#page/edit/$id");
	}
}	
?>